//
//  tItleVIew.m
//  HAODE
//
//  Created by panquanReabam.com on 16/1/14.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "tItleVIew.h"

#import "BigImages.h"
#import "HAODEsingleton.h"
@interface tItleVIew ()

{
    UIScrollView *mainScroll;
    UILabel *labelNumber;
    UILabel *labelDetail;
    
    UIView *backView;
    UIView *viewBottom;
    UIScrollView *imageScroll;
    
    
}
@property (nonatomic , assign) NSInteger currentPageIndex;
@property (nonatomic , assign) NSInteger totalPageCount;
@end

@implementation tItleVIew
{
    HAODEsingleton* commdity;}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        commdity=[HAODEsingleton shared];
        mainScroll = [[UIScrollView alloc]initWithFrame:self.bounds];
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:mainScroll];
        
        //滚动图片
        imageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 220)];
        [mainScroll addSubview:imageScroll];
        
        imageScroll.contentSize = CGSizeMake(ScreenWidth * _arrayImage.count, 220);
        imageScroll.pagingEnabled = YES;
        imageScroll.delegate = self;
        imageScroll.showsHorizontalScrollIndicator = NO;
        
        
        
        
               
        
        
        
        
        mainScroll.contentSize = CGSizeMake(ScreenWidth, 220);
        
    }
    return self;
}

- (void)setArrayImage:(NSArray *)arrayImage
{
    
    _arrayImage = arrayImage;
    for (int i=0; i<_arrayImage.count; i++) {
        BigImages *imageVC = [[BigImages alloc]initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, 220)];
        [imageVC setImageWithURL:[NSURL URLWithString:_arrayImage[i]] placeholderImage:[UIImage imageNamed:@"home.png"]];
        //       [imageVC getBigImage:_arrayImage[i]];
        //        imageVC.frame = CGRectMake(200*i, 0, 200, 220);
        [imageScroll addSubview:imageVC];
    }
    imageScroll.contentSize = CGSizeMake(ScreenWidth * _arrayImage.count, 220);
    labelNumber.text = [NSString stringWithFormat:@"%d/%lu",1,(unsigned long)_arrayImage.count];
    NSLog(@"------%lu",(unsigned long)_arrayImage.count);
}



#pragma mark -
#pragma mark - UIScrollViewDelegate



- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.page.currentPage = round(scrollView.contentOffset.x / scrollView.frame.size.width);
    
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
    
    self.page.currentPage = round(scrollView.contentOffset.x / scrollView.frame.size.width);
    NSLog(@"%ld",self.page.currentPage);
    
    
    labelNumber.text = [NSString stringWithFormat:@"%ld/%lu",self.page.currentPage+1,(unsigned long)_arrayImage.count];
}



@end